﻿using System.ComponentModel;
using System.Linq;
using FileSynchronizer.DataAccess;

namespace FileSynchronizer.Objects
{
    //---------------------------------------------------------------------------------------------------------------------------------------
    // Code based upon the State Pattern, as described by the GOF
    //
    // http://en.wikipedia.org/wiki/State_pattern and http://en.wikipedia.org/wiki/Talk:State_pattern#Disputed
    //
    // This is the abstract State Object
    //
    //---------------------------------------------------------------------------------------------------------------------------------------

    public abstract class ProgramState
    {
        #region Private variables
        //---------------------------------------------------------------------------------------------------------------------------------------
        private ProgramContext myProgramContext;
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructors
        //---------------------------------------------------------------------------------------------------------------------------------------
        public ProgramState(ProgramContext TheProgramContext)
        {
            myProgramContext = TheProgramContext;
        }
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Public variables and properties
        //---------------------------------------------------------------------------------------------------------------------------------------
        public ProgramContext CurrentProgramContext
        {
            get
            {
                return myProgramContext;
            }
        }
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Public Methods
        //---------------------------------------------------------------------------------------------------------------------------------------
        // Called when we want to change the state
        //---------------------------------------------------------------------------------------------------------------------------------------
        protected bool ChangeState(ProgramState NewProgramState)
        {
            if (myProgramContext != null)
            {
                return myProgramContext.ChangeState(NewProgramState);
            }
            else
            {
                return false;
            }
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual FileSynchronizerSettings LoadSettings()
        {
            return null;
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual bool SynchronizeAllFolderPairs(IQueryable<FolderPair> TheFolderPairs, RunWorkerCompletedEventHandler ExternalCompletionHandler)
        {
            return false;
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual bool DeleteFolderPair(FolderPair TheFolderPair, SyncDatabaseHelper TheSyncDatabaseHelper)
        {
            return false;
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual bool SynchronizeFolderPair(FolderPair TheFolderPair)
        {
            return false;
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual bool GotoIdleState()
        {
            return false;
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        public virtual bool RunNotMinimized()
        {
            return false;
        }
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion
    }

}
